package com.example.springbootdemo.controller;

import com.example.springbootdemo.dto.TestRedisSetDTO;
import com.example.springbootdemo.sevice.RedisService;
import com.example.springbootdemo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  redis控制器
 * </p>
 *
 * @author yurenwei
 * @since 2023/9/5
 */
@RestController
@RequestMapping("/api/redis")
public class RedisController {

    @Autowired
    private RedisService redisService;

    /**
     * 测试set方法
     *
     * @param params
     * @return
     */
    @PostMapping("/testSet")
    public Result testSet(@RequestBody TestRedisSetDTO params){
        redisService.testSet(params);
        return Result.ok();
    }

    /**
     * 测试get方法
     *
     * @return
     */
    @GetMapping("/testGet/{key}")
    public Result<String> testGet(@PathVariable String key){
        return Result.ok(redisService.testGet(key));
    }

    /**
     * 测试key过期
     *
     * @return
     */
    @PostMapping("/testKeyExpiration")
    public Result testKeyExpiration(){
        redisService.testKeyExpiration();
        return Result.ok();
    }

}
